package org.dding.msc.service.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;

import org.dding.msc.service.DependencyInfo;
import org.dding.msc.service.ServiceName;
import org.dding.msc.service.ServiceState;
import org.dding.msc.service.ServiceStateInfo;

public class ServiceStateImpl implements ServiceState {

	private ConcurrentHashMap<ServiceName, DependencyInfo> dependI = new ConcurrentHashMap<ServiceName, DependencyInfo>();
	private ConcurrentHashMap<ServiceName, DependencyInfo> iDepend = new ConcurrentHashMap<ServiceName, DependencyInfo>();
	private ConcurrentHashMap<ServiceName, ServiceStateInfo> serviceinfo = new ConcurrentHashMap<ServiceName, ServiceStateInfo>();

	@Override
	public void addDependI(DependencyInfo dependencyInfo) {
		dependI.put(dependencyInfo.getService(), dependencyInfo);
	}

	@Override
	public void addIDepend(DependencyInfo dependencyInfo) {
		iDepend.put(dependencyInfo.getService(), dependencyInfo);
	}

	@Override
	public DependencyInfo getIDepend(ServiceName service) {
		return iDepend.get(service);
	}

	@Override
	public DependencyInfo getDependI(ServiceName service) {
		return dependI.get(service);
	}

	@Override
	public void addDemand() {

	}

	@Override
	public void removeDemand() {

	}

	@Override
	public DependencyInfo removeIDepend(ServiceName service) {
		return iDepend.remove(service);
	}

	@Override
	public DependencyInfo removeDependI(ServiceName service) {
		return dependI.remove(service);
	}

	@Override
	public void addServiceState(ServiceStateInfo service) {
		serviceinfo.put(service.getService(), service);
	}

	@Override
	public ServiceStateInfo getServiceState(ServiceName service) {
		return serviceinfo.get(service);
	}

	@Override
	public Collection<ServiceStateInfo> getServiceStates() {
		return Collections.unmodifiableCollection(serviceinfo.values());
	}

	@Override
	public ServiceStateInfo removeServiceState(ServiceName service) {
		return serviceinfo.remove(service);
	}

	@Override
	public Collection<DependencyInfo> getIDepends() {
		return Collections.unmodifiableCollection(iDepend.values());
	}
}
